/*
vim: syntax=groovy
-*- mode: groovy;-*-
 * -------------------------------------------------
 *  ChromHMM Nextflow config file
 * -------------------------------------------------
 */

// Global default params, used in configs
params {
    outdir = "chromHMM"
 }

// Reference file paths
params {
    chromhmm {
        data = '/ref_genome/ChromHMM'
        jar = "${params.chromhmm.data}/ChromHMM.jar"
        anchor = "${params.chromhmm.data}/ANCHORFILES"
        chromsizes = "${params.chromhmm.data}/CHROMSIZES"
        coords = "${params.chromhmm.data}/COORDS"
    }
}

singularity.autoMounts = true
singularity.enabled = true
singularity.cacheDir ='/hpcapps-archive/opt/' 
process.container = '/hpcapps-archive/opt/chromhmm.1.17.simg'
process.executor = 'pbs' //'local' //'pbs'

timeline {
  enabled = true
  file = "${params.outdir}/ChIPseq_timeline.html"
}
trace {
  enabled = true
  file = "${params.outdir}/ChIPseq_trace.txt"
}
report {
  enabled = true
  file = "${params.outdir}/ChIPseq_report.html"
  }

// Capture exit codes from upstream processes when piping
process.shell = ['/bin/bash', '-euo', 'pipefail']

// Function to ensure that resource requirements don't go beyond
// a maximum limit
def check_max(obj, type) {
  if(type == 'memory'){
    if(obj.compareTo(params.max_memory) == 1)
      return params.max_memory
    else
      return obj
  } else if(type == 'time'){
    if(obj.compareTo(params.max_time) == 1)
      return params.max_time
    else
      return obj
  } else if(type == 'cpus'){
    return Math.min( obj, params.max_cpus )
  }
}
